<?php 
class Event_model extends CI_Model
{
	public function __construct(){}
	
	public function checkEvent($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
				
		$sql_select = array('event_name');
		$sql_whrere=array('event_name'=>$value);
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('event'));	
	    $result = $query->row();
	    if ($query->num_rows() > 0)
	    {
			return $query->row()->event_name;
	    }
		return FALSE;
	}
	
	public function addEvent($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$data=array(
				'event_name' => htmlspecialchars(strip_tags($value['eventname']),ENT_QUOTES),
				'event_description' => htmlspecialchars(strip_tags($value['description']),ENT_QUOTES),
				'event_category' => htmlspecialchars(strip_tags($value['category']),ENT_QUOTES),
				'event_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'event_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'event_status' => 'Active'
				);
			
		$key = $this->common_model->insertData('event', $data);
		return $key;
	}
	
	public function getEventByName($value='', $start='', $end='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		if($value == 'All' && $start == '' && $end == ''){
			$where = "(e.event_created_by=a.admin_id) AND (e.event_status!='Deleted') order by e.event_created_date DESC";
			$from = 'event e, admin a';
			$this->db->where($where);
			$this->db->select('*');
			$result = $this->db->get($this->db->dbprefix($from));
		}
		else if($value == 'All'){
			$where = "(e.event_created_by=a.admin_id) AND (e.event_status!='Deleted') order by e.event_created_date DESC";
			$from = 'event e, admin a';
			$result = $this->common_model->selectData($from, '*', $where, '', '', $start, $end);
		}
		else {
			$where = "(e.event_created_by=a.admin_id) AND (e.event_status!='Deleted')";
			$data = array('event_name' => $value);
			$from = 'event e, admin a';
			$result = $this->common_model->selectData($from, '*', $where, $data, '', $start, $end);
		}
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function getEventById($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "(e.event_id='".$value."') AND (e.event_created_by=a.admin_id)";
		$from = 'event e, admin a';
		$result = $this->common_model->selectData($from, '*', $where, '');
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function updateEventStatus($id, $value='')
	{

		if (empty($value))
		{
			return FALSE;
		}
		$status = array('event_status' => $value);
		$where = array('event_id' => $id);
		$this->db->where($where);
		$this->db->update($this->db->dbprefix('event'), $status);
	}
	
	public function updateEvent($value="")
	{
		if (empty($value))
		{
			return FALSE;
		}
		$date=date('Y-m-d H:i:s');
		$id = $value['event_id'];
		$data=array(
				'event_name' => htmlspecialchars(strip_tags($value['eventname']),ENT_QUOTES),
				'event_description' => htmlspecialchars(strip_tags($value['description']),ENT_QUOTES),
				'event_category' => htmlspecialchars(strip_tags($value['category']),ENT_QUOTES),
				'event_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'event_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'event_status' => 'Active'
				);
		$where = array('event_id' => $id);
		$this->db->where($where);
		$this->db->update($this->db->dbprefix('event'), $data);
	}
	
	public function getAllFormField($value='',$type='',$cat='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "";
		if($value == 'application'){
			if($cat != '')
			{
				$where .= "(master_application_form_category='".$cat."') AND ";
			}
			$where .= "(master_application_form_subcategory='".$type."') AND (master_application_form_status='Active')";
			$from = 'master_application_form';
			$result = $this->common_model->selectData($from, '*', $where, '');	
		}
		if($value == 'nomination'){
			if($type == '')
			{
				$where = "(master_nomination_form_category='".$cat."') AND (master_nomination_form_status='Active')";
			}else{
				if($cat != '')
				{
					$where .= "(master_nomination_form_category='".$cat."') AND ";
				}
				$where = "(master_nomination_form_subcategory='".$type."') AND (master_nomination_form_status='Active')";
			}
			$from = 'master_nomination_form';
			$result = $this->common_model->selectData($from, '*', $where, '');
		}
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function checkEventForm($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
				
		$sql_select = array('event_application_form_event_id');
		$sql_whrere=array('event_application_form_event_id'=>$value, 'event_application_form_status'=>'Active');
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('event_application_form'));	
	    $result = $query->row();
	    if ($query->num_rows() > 0)
	    {
			return $query->row()->event_application_form_event_id;
	    }
		return FALSE;
	}

	public function checkEventNominationForm($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
				
		$sql_select = array('event_nomination_form_event_id');
		$sql_whrere=array('event_nomination_form_event_id'=>$value, 'event_nomination_form_status'=>'Active');
		$query = $this->db->select($sql_select)->where($sql_whrere)->get($this->db->dbprefix('event_nomination_form'));	
	    $result = $query->row();
	    if ($query->num_rows() > 0)
	    {
			return $query->row()->event_application_form_event_id;
	    }
		return FALSE;
	}

	public function addEventForm($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$status = 'Active';
		
		$header = array(
					'event_application_event_id' => htmlspecialchars(strip_tags($value['choose_event']),ENT_QUOTES),
					'event_application_form_url' => htmlspecialchars(strip_tags(BASE_URL.'/user/application?event='.base64_encode($value['choose_event'])),ENT_QUOTES),
					'event_application_form_activation' => htmlspecialchars(strip_tags($value['activation_status']),ENT_QUOTES),
					'event_application_form_header' => htmlspecialchars(strip_tags($value['form_header']),ENT_QUOTES),
					'event_application_form_footer' => htmlspecialchars(strip_tags($value['form_footer']),ENT_QUOTES),
					'event_application_form_thank_you_page' => htmlspecialchars(strip_tags($value['thanks_page']),ENT_QUOTES),
					'event_application_form_declined_page' => htmlspecialchars(strip_tags($value['decline_page']),ENT_QUOTES),
					);
		$head_key = $this->common_model->insertData('event_application_form_headers', $header);
		
		for($i=1;$i<=18;$i++)
		{
			if(isset($value['ap_field'.$i]) && $value['ap_field'.$i] != '')
			{
				$man = 'Yes';
				if((isset($value['ap_field2']) && $value['ap_field2'] != '') || (isset($value['ap_field6']) && $value['ap_field6'] != '') || (isset($value['ap_field7']) && $value['ap_field7'] != '') || (isset($value['ap_field8']) && $value['ap_field8'] != '') || (isset($value['ap_field10']) && $value['ap_field10'] != '') || (isset($value['ap_field12']) && $value['ap_field12'] != '') || (isset($value['ap_field18']) && $value['ap_field'] != ''))
				{
					$man = 'No';
				}
				$data=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($value['choose_event']),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$i.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$i]),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Applicant Particulars'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key = $this->common_model->insertData('event_application_form', $data);
			}
		}
		
		for($n=19;$n<=38;$n++)
		{
			if(isset($value['ap_field'.$n.'_text']) && $value['ap_field'.$n.'_text'] != '')
			{
				if($value['ap_field'.$n.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data1=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($value['choose_event']),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$n.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$n.'_text']),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Applicant Particulars'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key1 = $this->common_model->insertData('event_application_form', $data1);
			}
		}

		for($m=39;$m<=52;$m++)
		{
			if(isset($value['ap_field'.$m]) && $value['ap_field'.$m] != '')
			{
				$man='No';
				$data2=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($value['choose_event']),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$m.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$m]),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Educational Background'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key2 = $this->common_model->insertData('event_application_form', $data2);
			}
		}
		
		for($a=53;$a<=72;$a++)
		{
			if(isset($value['ap_field'.$a.'_text']) && $value['ap_field'.$a.'_text'] != '')
			{
				if(isset($value['ap_field'.$a.'_1']) && $value['ap_field'.$a.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data3=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($value['choose_event']),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$a.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$a.'_text']),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Educational Background'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key3 = $this->common_model->insertData('event_application_form', $data3);
			}
		}
		
		for($b=73;$b<=78;$b++)
		{
			if(isset($value['ap_field'.$b]) && $value['ap_field'.$b] != '')
			{
				if($value['ap_field'.$b.'1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data4=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($value['choose_event']),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$b.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$b]),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Document'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key4 = $this->common_model->insertData('event_application_form', $data4);
			}
		}
		
		return $key;
	}
	
	public function addEventNominationForm($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$status = 'Active';
		
		$header = array(
					'event_nomination_event_id' => htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES),
					'event_nomination_form_url' => htmlspecialchars(strip_tags(urlencode(BASE_URL.'/user/nomination?event='.$value['choose_event1'].now())),ENT_QUOTES),
					'event_nomination_form_activation' => htmlspecialchars(strip_tags($value['activation_status1']),ENT_QUOTES),
					'event_nomination_form_header' => htmlspecialchars(strip_tags($value['form_header1']),ENT_QUOTES),
					'event_nomination_form_footer' => htmlspecialchars(strip_tags($value['form_footer1']),ENT_QUOTES),
					'event_nomination_form_thank_you_page' => htmlspecialchars(strip_tags($value['thanks_page1']),ENT_QUOTES),
					'event_nomination_form_declined_page' => htmlspecialchars(strip_tags($value['decline_page1']),ENT_QUOTES),
					);
		$head_key = $this->common_model->insertData('event_nomination_form_headers', $header);
		
		for($i=1;$i<=18;$i++)
		{
			if(isset($value['nom_field'.$i]) && $value['nom_field'.$i] != '')
			{
				$man = 'Yes';
				if((isset($value['nom_field2']) && $value['nom_field2'] != '') || (isset($value['nom_field6']) && $value['nom_field6'] != '') || (isset($value['nom_field7']) && $value['nom_field7'] != '') || (isset($value['nom_field8']) && $value['nom_field8'] != '') || (isset($value['nom_field9']) && $value['nom_field9'] != '') || (isset($value['nom_field10']) && $value['nom_field10'] != '') || (isset($value['nom_field12']) && $value['nom_field12'] != '') || (isset($value['nom_field18']) && $value['nom_field'] != ''))
				{
					$man = 'No';
				}
				$data=array(
					'event_nomination_form_event_id' => htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES),
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$i.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$i]),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominee'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key = $this->common_model->insertData('event_nomination_form', $data);
			}
		}
		
		for($n=19;$n<=24;$n++)
		{
			if(isset($value['nom_field'.$n.'_text']) && $value['nom_field'.$n.'_text'] != '')
			{
				if($value['nom_field'.$n.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data1=array(
					'event_nomination_form_event_id' => htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES),
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$n.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$n.'_text']),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominee'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key1 = $this->common_model->insertData('event_nomination_form', $data1);
			}
		}
		for($m=25;$m<=33;$m++)
		{
			if(isset($value['nom_field'.$m]) && $value['nom_field'.$m] != '')
			{
				$man = 'Yes';
				if((isset($value['nom_field26']) && $value['nom_field26'] != '') || (isset($value['nom_field30']) && $value['nom_field30'] != '') || (isset($value['nom_field31']) && $value['nom_field31'] != '') || (isset($value['nom_field33']) && $value['nom_field33'] != ''))
				{
					$man = 'No';
				}
				$data2=array(
					'event_nomination_form_id'=> NULL,
					'event_nomination_form_event_id' => htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES),
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$m.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$m]),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominating Party'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				//$key2 = $this->common_model->insertData('event_nomination_form', $data2);
				$this->db->insert('event_nomination_form',$data2);
			}
		}
		for($a=34;$a<=39;$a++)
		{
			if(isset($value['nom_field'.$a.'_text']) && $value['nom_field'.$a.'_text'] != '')
			{
				if(isset($value['nom_field'.$a.'_1']) && $value['nom_field'.$a.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data3=array(
					'event_nomination_form_event_id' => htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES),
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$a.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$a.'_text']),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominating Party'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key3 = $this->common_model->insertData('event_nomination_form', $data3);
			}
		}
		
		for($b=40;$b<=43;$b++)
		{
			if(isset($value['nom_field'.$b]) && $value['nom_field'.$b] != '')
			{
				$man='No';
				$data4=array(
					'event_nomination_form_event_id' => htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES),
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$b.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$b]),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Disclosure Notice'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key4 = $this->common_model->insertData('event_nomination_form', $data4);
			}
		}
		
		return $key;
	}
	
	public function addAward($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		
		if(!empty($value['file']['award_file']['name'])) {
			//validate uploaded file
			$allowedExts = array("gif", "jpeg", "jpg", "png");
			$info = pathinfo($value['file']['award_file']['name']);
			$ext = $info['extension'];
		
			if ((($value['file']['award_file']["type"] != "image/jpeg") || ($value['file']['award_file']["type"] != "image/gif") || ($value['file']['award_file']["type"] != "image/png")) && !in_array($ext, $allowedExts)){
				$this->session->set_userdata('award_success1', $value['file']['award_file']['name']." is not a valid image format");
				return false;
			}
			else if($value['file']['award_file']["size"] > 2097152){
				$this->session->set_userdata('award_success1', "File size cannot be exceed 2MB");
				return false;
			}
			else if ($value['file']['award_file']["error"] > 0){
				$this->session->set_userdata('award_success1', "Return Code: ".$value['file']["award_file"]["error"]);
				return false;
			}
		}

		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$data=array(
				'award_event_id' => htmlspecialchars(strip_tags($value['selectevent']),ENT_QUOTES),
				'award_name' => htmlspecialchars(strip_tags($value['awardname']),ENT_QUOTES),
				'award_description' => htmlspecialchars(strip_tags($value['description2']),ENT_QUOTES),
				'award_incharge_id' => htmlspecialchars(strip_tags($value['admin_select']),ENT_QUOTES),
				'award_current_status' => htmlspecialchars(strip_tags($value['status_select']),ENT_QUOTES),
				'award_refree_count' => htmlspecialchars(strip_tags($value['refree_select']),ENT_QUOTES),
				'award_start_date' => htmlspecialchars(strip_tags(date("Y-m-d H:i:s", strtotime($value['startdate']))),ENT_QUOTES),
				'award_end_date' => htmlspecialchars(strip_tags(date("Y-m-d H:i:s", strtotime($value['enddate']))),ENT_QUOTES),
				'award_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_status' => 'Active'
				);
			
		$key = $this->common_model->insertData('award', $data);
		
		$data1=array(
				'award_panelist_award_id' => htmlspecialchars(strip_tags($key),ENT_QUOTES),
				'award_panelist_admin_id' => htmlspecialchars(strip_tags($value['cp_select']),ENT_QUOTES),
				'award_panelist_type' => htmlspecialchars(strip_tags('Chief Panelist'),ENT_QUOTES),
				'award_panelist_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_panelist_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_panelist_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
		$key1 = $this->common_model->insertData('award_panelist', $data1);
			
		if(!empty($value['file']['award_file']['name'])) {
			$newname = 'award_logo_'.$key.".".$ext;
			$target = UPLOAD_URL.'/award_logo/'.$newname;
			@unlink(UPLOAD_URL.'/award_logo/'.$newname);
			move_uploaded_file($value['file']['award_file']["tmp_name"],$target);
				
			$file=array('award_logo_path'=> $target);
			$where = array('award_id' => $key);
			$this->db->where($where);
			$this->db->update($this->db->dbprefix('award'), $file);
		}
				
		return $key;
	}

	public function addAwardPanelist($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		
		$this->db->query("delete from scopus_award_panelist where award_panelist_award_id='".$value['select_award_id']."' and award_panelist_type='Panelist'");
		
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		foreach($value['panelist'] as $temp)
		{
			$data=array(
				'award_panelist_award_id' => htmlspecialchars(strip_tags($value['select_award_id']),ENT_QUOTES),
				'award_panelist_admin_id' => htmlspecialchars(strip_tags($temp),ENT_QUOTES),
				'award_panelist_type' => htmlspecialchars(strip_tags('Panelist'),ENT_QUOTES),
				'award_panelist_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_panelist_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_panelist_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
			$key = $this->common_model->insertData('award_panelist', $data);
		}
		
		return $key;
	}
	
	public function checkAwardByName($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "(award_name='".$value."') AND (award_status='Active')";
		$from = 'award';
		$this->db->where($where);
		$this->db->select('*');
		$result = $this->db->get($this->db->dbprefix($from));
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function checkAwardCriteria($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "(award_criteria_award_id='".$value."') AND (award_criteria_status='Active')";
		$from = 'award_criteria';
		$this->db->where($where);
		$this->db->select('*');
		$result = $this->db->get($this->db->dbprefix($from));
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function getCriteriaById($id)
	{
		$from = 'award_criteria';
		$where = "(award_criteria_award_id='".$id."')";
		$this->db->where($where);
		$this->db->select('*');
		$result = $this->db->get($this->db->dbprefix($from));
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function masterCriteria()
	{
		$from = 'master_award_criteria';
		$this->db->select('*');
		$result = $this->db->get($this->db->dbprefix($from));
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function addAwardCriteria($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}

		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$a_id = $value['select_award_id'];
		$keys = array_keys($value);
		$count = 0;
		for($j=0;$j<=count($keys)-1;$j++)
		{
			if(stristr($keys[$j], 'criteria_label'))
			{
				$count++;
			}
		}
		for($i=1;$i<=$count;$i++)
		{
			$data=array(
				'award_criteria_award_id' => htmlspecialchars(strip_tags($a_id),ENT_QUOTES),
				'award_criteria_label' => htmlspecialchars(strip_tags($value['criteria_label'.$i]),ENT_QUOTES),
				'award_criteria_value' => htmlspecialchars(strip_tags($value['criteria_value'.$i]),ENT_QUOTES),
				'award_criteria_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_criteria_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_criteria_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
			$key = $this->common_model->insertData('award_criteria', $data);
			if(isset($value['sub_criteria_l'.$i]) && !empty($value['sub_criteria_l'.$i]))
			{
				for($n=0;$n<=count($value['sub_criteria_l'.$i])-1;$n++)
				{
					$data1=array(
						'award_criteria_award_id' => htmlspecialchars(strip_tags($a_id),ENT_QUOTES),
						'award_criteria_parent_id' => htmlspecialchars(strip_tags($key),ENT_QUOTES),
						'award_criteria_label' => htmlspecialchars(strip_tags($value['sub_criteria_l'.$i][$n]),ENT_QUOTES),
						'award_criteria_value' => htmlspecialchars(strip_tags($value['sub_criteria_v'.$i][$n]),ENT_QUOTES),
						'award_criteria_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
						'award_criteria_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
						'award_criteria_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
						);
					$key1 = $this->common_model->insertData('award_criteria', $data1);
				}
			}
		}
		$data2=array(
			'award_criteria_award_id' => htmlspecialchars(strip_tags($a_id),ENT_QUOTES),
			'award_criteria_label' => htmlspecialchars(strip_tags('Scoring'),ENT_QUOTES),
			'award_criteria_value' => htmlspecialchars(strip_tags($value['scoring2']),ENT_QUOTES),
			'award_criteria_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
			'award_criteria_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
			'award_criteria_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
			);
		$this->common_model->insertData('award_criteria', $data2);
		
		return $key;
	}
	
	public function updateAwardCriteria($value='', $cat)
	{
		if (empty($value))
		{
			return FALSE;
		}
		
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$a_id = htmlspecialchars(strip_tags($value['select_award_id']),ENT_QUOTES);
		array_pop($value);
		array_pop($value);
		
		$this->db->query("DELETE FROM scopus_award_criteria WHERE award_criteria_award_id='".$a_id."'");
		
		$i=0;
		foreach($value as $key => $row){
			if($row == ''){
				if($key != 'mc1_label' || $key != 'mc2_label' || $key != 'mc3_label'){
					$i++;	
				}
				continue;
			}
			$data=array(
				'award_criteria_award_id' => htmlspecialchars(strip_tags($a_id),ENT_QUOTES),
				'award_criteria_id_fk' => htmlspecialchars(strip_tags($cat[$i]['award_criteria_id']),ENT_QUOTES),
				'award_criteria_value' => htmlspecialchars(strip_tags($row),ENT_QUOTES),
				'award_criteria_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_criteria_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_criteria_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
			
		$key = $this->common_model->insertData('award_criteria', $data);
		$i++;
		}
		
		return $key;
	}
	
	public function getAllAwards()
	{
		$query = "select temp.id, temp.e_name, temp.a_name, temp.incharge, temp1.chief, temp.status from (SELECT award.award_id as id,event.event_name as e_name, award.award_name as a_name, award.award_id as a_id, admin.admin_fullname as incharge, award.award_current_status as status FROM `scopus_award`  AS award, scopus_event AS event, scopus_admin AS admin WHERE event.event_id = award.award_event_id AND admin.admin_id = award.award_incharge_id and award.award_status!='Deleted') temp left join (SELECT admin.admin_fullname as chief, award.award_id as awardid FROM `scopus_award`  AS award, scopus_award_panelist AS panelist, scopus_admin AS admin WHERE panelist.award_panelist_admin_id=admin.admin_id AND panelist.award_panelist_award_id=award.award_id and panelist.award_panelist_type='Chief Panelist') temp1 on temp1.awardid=temp.a_id";
		$result = $this->db->query($query);
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function updateAwardStatus($id, $value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$status = array('award_status' => $value);
		$where = array('award_id' => $id);
		$this->db->where($where);
		$this->db->update($this->db->dbprefix('award'), $status);
		return TRUE;
	}
	
	public function getAwardById($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "(a.award_id='".$value."') AND (a.award_id=p.award_panelist_award_id)";
		$from = 'award a, award_panelist p';
		$result = $this->common_model->selectData($from, '*', $where, '');
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function updateAward($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$a_id = $value['select_award_id'];
		$data=array(
				'award_event_id' => htmlspecialchars(strip_tags($value['selectevent']),ENT_QUOTES),
				'award_name' => htmlspecialchars(strip_tags($value['awardname']),ENT_QUOTES),
				'award_description' => htmlspecialchars(strip_tags($value['description2']),ENT_QUOTES),
				'award_incharge_id' => htmlspecialchars(strip_tags($value['admin_select']),ENT_QUOTES),
				'award_current_status' => htmlspecialchars(strip_tags($value['status_select']),ENT_QUOTES),
				'award_refree_count' => htmlspecialchars(strip_tags($value['refree_select']),ENT_QUOTES),
				'award_start_date' => htmlspecialchars(strip_tags(date("Y-m-d H:i:s", strtotime($value['startdate']))),ENT_QUOTES),
				'award_end_date' => htmlspecialchars(strip_tags(date("Y-m-d H:i:s", strtotime($value['enddate']))),ENT_QUOTES),
				'award_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_status' => 'Active'
				);
				
			$where = array('award_id' => $a_id);
			$this->db->where($where);
			$this->db->update($this->db->dbprefix('award'), $data);
		
		$data1=array(
				'award_panelist_award_id' => htmlspecialchars(strip_tags($a_id),ENT_QUOTES),
				'award_panelist_admin_id' => htmlspecialchars(strip_tags($value['cp_select']),ENT_QUOTES),
				'award_panelist_type' => htmlspecialchars(strip_tags('Chief Panelist'),ENT_QUOTES),
				'award_panelist_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'award_panelist_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'award_panelist_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
		
		$where1 = array('award_panelist_award_id' => $a_id);
		$this->db->where($where1);
		$this->db->update($this->db->dbprefix('award_panelist'), $data1);
		
		//validate uploaded file
		$allowedExts = array("gif", "jpeg", "jpg", "png");
		$info = pathinfo($value['file']['award_file']['name']);
		$ext = $info['extension'];
			
		if(!empty($value['file']['award_file']['name'])) {
			if ((($value['file']['award_file']["type"] != "image/jpeg") || ($value['file']['award_file']["type"] != "image/gif") || ($value['file']['award_file']["type"] != "image/png")) && !in_array($ext, $allowedExts)){
				$this->session->set_uerdata('award_success1', $value['file']['award_file']['name']." is not a valid image format");
				return false;
			}
			else if($value['file']['award_file']["size"] > 2097152){
				$this->session->set_uerdata('award_success1', "File size cannot be exceed 2MB");
				return false;
			}
			else if ($value['file']['award_file']["error"] > 0){
				$this->session->set_uerdata('award_success1', "Return Code: ".$value['file']["award_file"]["error"]);
				return false;
			}
			else {
				$newname = 'award_logo_'.$a_id.".".$ext;
				$target = UPLOAD_URL.'/award_logo/'.$newname;
				@unlink(UPLOAD_URL.'/award_logo/'.$newname);
				move_uploaded_file($value['file']['award_file']["tmp_name"],$target);
				
				$file=array('award_logo_path'=> $target);
				$where = array('award_id' => $a_id);
				$this->db->where($where);
				$this->db->update($this->db->dbprefix('award'), $file);
			}
		}
				
		return $key;
	}
	
	public function addEventFaq($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}

		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		
		$data=array(
				'event_faq_event_id' => htmlspecialchars(strip_tags($value['faq_event']),ENT_QUOTES),
				'event_faq_question' => htmlspecialchars(strip_tags($value['faq_q']),ENT_QUOTES),
				'event_faq_answer' => htmlspecialchars(strip_tags($value['faq_a']),ENT_QUOTES),
				'event_faq_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
				'event_faq_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
				'event_faq_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
				
		$key = $this->common_model->insertData('event_faq', $data);
		
		return $key;
	}
	
	public function changeFaqStatus($id, $value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$status = array('event_faq_status' => $value);
		$where = array('event_faq_id' => $id);
		$this->db->where($where);
		$this->db->update($this->db->dbprefix('event_faq'), $status);
		return TRUE;
	}
	
	public function getFaqByEvent($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "(event_faq_event_id='".$value."') AND (event_faq_status='Active')";
		$from = 'event_faq';
		$result = $this->common_model->selectData($from, '*', $where, '');
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}

	public function addEventVideo($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}

		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		
		$data=array(
				'event_videos_event_id' => htmlspecialchars(strip_tags($value['video_event']),ENT_QUOTES),
				'event_videos_name' => htmlspecialchars(strip_tags($value['video_name']),ENT_QUOTES),
				'event_videos_link' => htmlspecialchars(strip_tags($value['video_link']),ENT_QUOTES),
				'event_videos_status' => htmlspecialchars(strip_tags('Active'),ENT_QUOTES),
				);
				
		$key = $this->common_model->insertData('event_videos', $data);
		return $key;
	}
	
	public function changeVideoStatus($id, $value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$status = array('event_videos_status' => $value);
		$where = array('event_videos_id' => $id);
		$this->db->where($where);
		$this->db->update($this->db->dbprefix('event_videos'), $status);
		return TRUE;
	}
	
	public function getVideoByEvent($value='')
	{
		if (empty($value))
		{
			return FALSE;
		}
		$where = "(event_videos_event_id='".$value."') AND (event_videos_status='Active')";
		$from = 'event_videos';
		$result = $this->common_model->selectData($from, '*', $where, '');
		
		$resultData=array();
		if($result->num_rows()>0){
			$resultData = $result->result_array();
		}
		return $resultData;
	}
	
	public function get_field_data($category){
		$this->db->select('event_application_form_label');
		$this->db->select('event_application_form_mandatory');
		$this->db->select('event_application_form_field_id');
		$this->db->where('event_application_form_event_id',$this->session->userdata('edit_event'));
		$this->db->where(array('event_application_form_status'=>'Active', 'event_application_form_category' => $category));
		$query = $this->db->get('scopus_event_application_form');
		$resultData=array(); 
		if($query->num_rows()>0){
			foreach($query->result() as $row)
			{
			  $resultData['label'][$row->event_application_form_field_id] = $row->event_application_form_label;
			  $resultData['mandatory'][$row->event_application_form_field_id] =$row->event_application_form_mandatory;
			  $resultData['field_id'][] = $row->event_application_form_field_id;
			}
		}
		return $resultData;
	}
	
	public function get_field_data_nomination($category){
		$this->db->select('event_nomination_form_label');
		$this->db->select('event_nomination_form_field_id');
		$this->db->where('event_nomination_form_event_id',$this->session->userdata('edit_event'));
		$this->db->where(array('event_nomination_form_status'=>'Active', 'event_nomination_form_category' => $category));
		$query = $this->db->get('scopus_event_nomination_form');
		$resultData=array(); 
		if($query->num_rows()>0){
			foreach($query->result() as $row)
			{
			  $resultData['label'][$row->event_nomination_form_field_id] = $row->event_nomination_form_label;
			  $resultData['field_id'][] = $row->event_nomination_form_field_id;
			}
		}
		return $resultData;
	}
	
	
	public function get_header_data($type,$table){
		$this->db->where($type,$this->session->userdata('edit_event'));
		$query = $this->db->get($table);
		$resultData=array();
		if($query->num_rows()>0){
			$resultData = $query->result_array();
		}
		return $resultData;
	}
	
	public function editEventForm($value='')
	{
	
		if (empty($value))
		{
			return FALSE;
		}
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$status = 'Active';
		$header = array();
		if(!empty($value['choose_event'])){
			$header['event_application_form_url'] = htmlspecialchars(strip_tags(BASE_URL.'/user/application?event='.base64_encode($value['choose_event'])),ENT_QUOTES);
		}
		if(!empty($value['activation_status'])){	
			$header['event_application_form_activation'] = htmlspecialchars(strip_tags($value['activation_status']),ENT_QUOTES);
		}
		if(!empty($value['form_header'])){
			$header['event_application_form_header'] = htmlspecialchars(strip_tags($value['form_header']),ENT_QUOTES);
		}
		if(!empty($value['form_footer'])){
			$header['event_application_form_footer'] = htmlspecialchars(strip_tags($value['form_footer']),ENT_QUOTES);
		}
		if(!empty($value['thanks_page'])){
			$header['event_application_form_thank_you_page'] = htmlspecialchars(strip_tags($value['thanks_page']),ENT_QUOTES);
		}
		if(!empty($value['decline_page'])){
			$header['event_application_form_declined_page'] = htmlspecialchars(strip_tags($value['decline_page']),ENT_QUOTES);
		}
		$event_id = htmlspecialchars(strip_tags($this->input->post('event_id')),ENT_QUOTES);
		$this->db->where('event_application_event_id',$event_id);
		$this->db->update('scopus_event_application_form_headers',$header);
		//$head_key = $this->common_model->insertData('event_application_form_headers', $header);
		$this->db->delete('event_application_form', array('event_application_form_event_id' => $event_id)); 
		for($i=1;$i<=18;$i++)
		{
			if(isset($value['ap_field'.$i]) && $value['ap_field'.$i] != '')
			{
				$man = 'Yes';
				if((isset($value['ap_field2']) && $value['ap_field2'] != '') || (isset($value['ap_field6']) && $value['ap_field6'] != '') || (isset($value['ap_field7']) && $value['ap_field7'] != '') || (isset($value['ap_field8']) && $value['ap_field8'] != '') || (isset($value['ap_field10']) && $value['ap_field10'] != '') || (isset($value['ap_field12']) && $value['ap_field12'] != '') || (isset($value['ap_field18']) && $value['ap_field'] != ''))
				{
					$man = 'No';
				}
				$data=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($event_id),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$i.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$i]),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Applicant Particulars'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key = $this->common_model->insertData('event_application_form', $data);
			}
		}
		
		for($n=19;$n<=38;$n++)
		{
			if(isset($value['ap_field'.$n.'_text']) && $value['ap_field'.$n.'_text'] != '')
			{
				if($value['ap_field'.$n.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data1=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($event_id),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$n.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$n.'_text']),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Applicant Particulars'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key1 = $this->common_model->insertData('event_application_form', $data1);
			}
		}

		for($m=39;$m<=52;$m++)
		{
			if(isset($value['ap_field'.$m]) && $value['ap_field'.$m] != '')
			{
				$man='No';
				$data2=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($event_id),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$m.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$m]),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Educational Background'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key2 = $this->common_model->insertData('event_application_form', $data2);
			}
		}
		
		for($a=53;$a<=72;$a++)
		{
			if(isset($value['ap_field'.$a.'_text']) && $value['ap_field'.$a.'_text'] != '')
			{
				if(isset($value['ap_field'.$a.'_1']) && $value['ap_field'.$a.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data3=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($event_id),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$a.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$a.'_text']),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Educational Background'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key3 = $this->common_model->insertData('event_application_form', $data3);
			}
		}
		
		for($b=73;$b<=78;$b++)
		{
			if(isset($value['ap_field'.$b]) && $value['ap_field'.$b] != '')
			{
				if($value['ap_field'.$b.'1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data4=array(
					'event_application_form_event_id' => htmlspecialchars(strip_tags($event_id),ENT_QUOTES),
					'event_application_form_field_id' => htmlspecialchars(strip_tags($value['ap_field'.$b.'_id']),ENT_QUOTES),
					'event_application_form_label' => htmlspecialchars(strip_tags($value['ap_field'.$b]),ENT_QUOTES),
					'event_application_form_category' => htmlspecialchars(strip_tags('Document'),ENT_QUOTES),
					'event_application_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_application_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_application_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_application_form_status' => $status
					);
				$key4 = $this->common_model->insertData('event_application_form', $data4);
			}
		}
		
		return $key;
	}
	
	public function editEventNominationForm($value='')
	{
		//var_dump($value);die();
		if (empty($value))
		{
			return FALSE;
		}
		$date=date('Y-m-d H:i:s');
		$id = $this->session->userdata('admin_id');
		$status = 'Active';
		$event_id = htmlspecialchars(strip_tags($this->input->post('event_id')),ENT_QUOTES);
		$header = array();
		//htmlspecialchars(strip_tags($value['choose_event1']),ENT_QUOTES);
		//$header['event_nomination_event_id'] = $this->input->post('event_id');	
		$header['event_nomination_form_url'] = htmlspecialchars(strip_tags(BASE_URL.'/user/nomination?event='.base64_encode($value['choose_event1'])),ENT_QUOTES);
		$header['event_nomination_form_activation'] = htmlspecialchars(strip_tags($value['activation_status1']),ENT_QUOTES);
		$header['event_nomination_form_header'] = htmlspecialchars(strip_tags($value['form_header1']),ENT_QUOTES);
		$header['event_nomination_form_footer'] = htmlspecialchars(strip_tags($value['form_footer1']),ENT_QUOTES);
		$header['event_nomination_form_thank_you_page'] = htmlspecialchars(strip_tags($value['thanks_page1']),ENT_QUOTES);
		$header['event_nomination_form_declined_page'] = htmlspecialchars(strip_tags($value['decline_page1']),ENT_QUOTES);
		
		//$head_key = $this->common_model->insertData('event_nomination_form_headers', $header);
		$this->db->where('event_nomination_event_id',$event_id);
		$this->db->update('scopus_event_nomination_form_headers',$header);
				
		for($i=1;$i<=18;$i++)
		{
			if(isset($value['nom_field'.$i]) && $value['nom_field'.$i] != '')
			{
				$man = 'Yes';
				if((isset($value['nom_field2']) && $value['nom_field2'] != '') || (isset($value['nom_field6']) && $value['nom_field6'] != '') || (isset($value['nom_field7']) && $value['nom_field7'] != '') || (isset($value['nom_field8']) && $value['nom_field8'] != '') || (isset($value['nom_field9']) && $value['nom_field9'] != '') || (isset($value['nom_field10']) && $value['nom_field10'] != '') || (isset($value['nom_field12']) && $value['nom_field12'] != '') || (isset($value['nom_field18']) && $value['nom_field'] != ''))
				{
					$man = 'No';
				}
				$data=array(
					'event_nomination_form_event_id' => $event_id,
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$i.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$i]),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominee'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
					
				
				$key = $this->common_model->insertData('event_nomination_form', $data);
			}
		}
		
		for($n=19;$n<=24;$n++)
		{
			if(isset($value['nom_field'.$n.'_text']) && $value['nom_field'.$n.'_text'] != '')
			{
				if($value['nom_field'.$n.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data1=array(
					'event_nomination_form_event_id' => $event_id,
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$n.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$n.'_text']),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominee'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key1 = $this->common_model->insertData('event_nomination_form', $data1);
			}
		}

		for($m=25;$m<=33;$m++)
		{
			if(isset($value['nom_field'.$i]) && $value['nom_field'.$i] != '')
			{
				$man = 'Yes';
				if((isset($value['nom_field26']) && $value['nom_field26'] != '') || (isset($value['nom_field30']) && $value['nom_field30'] != '') || (isset($value['nom_field31']) && $value['nom_field31'] != '') || (isset($value['nom_field33']) && $value['nom_field33'] != ''))
				{
					$man = 'No';
				}
				$data2=array(
					'event_nomination_form_event_id' => $event_id,
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$i.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$i]),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominating Party'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key2 = $this->common_model->insertData('event_nomination_form', $data2);
			}
		}
		
		for($a=34;$a<=39;$a++)
		{
			if(isset($value['nom_field'.$a.'_text']) && $value['nom_field'.$a.'_text'] != '')
			{
				if(isset($value['nom_field'.$a.'_1']) && $value['nom_field'.$a.'_1'] != '')
				{
					$man = 'Yes';
				}else {
					$man='No';
				}
				$data3=array(
					'event_nomination_form_event_id' => $event_id,
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$a.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$a.'_text']),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Nominating Party'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key3 = $this->common_model->insertData('event_nomination_form', $data3);
			}
		}
		
		for($b=40;$b<=43;$b++)
		{
			if(isset($value['nom_field'.$b]) && $value['nom_field'.$b] != '')
			{
				$man='No';
				$data4=array(
					'event_nomination_form_event_id' => $event_id,
					'event_nomination_form_field_id' => htmlspecialchars(strip_tags($value['nom_field'.$b.'_id']),ENT_QUOTES),
					'event_nomination_form_label' => htmlspecialchars(strip_tags($value['nom_field'.$b]),ENT_QUOTES),
					'event_nomination_form_category' => htmlspecialchars(strip_tags('Disclosure Notice'),ENT_QUOTES),
					'event_nomination_form_mandatory' => htmlspecialchars(strip_tags($man),ENT_QUOTES),
					'event_nomination_form_created_by' => htmlspecialchars(strip_tags($id),ENT_QUOTES),
					'event_nomination_form_created_date' => htmlspecialchars(strip_tags($date),ENT_QUOTES),
					'event_nomination_form_status' => $status
					);
				$key4 = $this->common_model->insertData('event_nomination_form', $data4);
			}
		}
		
		return $key;
	}
	
}
/* End of file event_model.php */
/* Location: ./application/models/event_model.php */